package com.thti.mecool.client.adapter;

import java.util.Arrays;
import java.util.HashMap;

import com.thti.mecool.client.activity.R;
import com.thti.mecool.client.activity.TaskExecute;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TaskOptionAdapter extends BaseAdapter {
	private int[] ActionIds = null;
	Context context;
	HashMap<String, Integer> finishStat;
	String[] newCert,StepIds;
	
	public TaskOptionAdapter(Context context, String[] newCert, int[] actionIds, HashMap<String, Integer> finishStat, String[] stepIds) {
		this.context=context;
		this.newCert=newCert;
		this.ActionIds=actionIds;
		this.finishStat=finishStat;
		this.StepIds=stepIds;
	}
	@Override
	public int getCount() {
		
		return newCert.length;
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return newCert[position];
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		convertView=LayoutInflater.from(context).inflate(R.layout.mecool_task_option_item, null);
		TextView task_option_item_text=(TextView)convertView.findViewById(R.id.task_option_item_text);
		ImageView task_option_item_img=(ImageView)convertView.findViewById(R.id.task_option_item_img);
		ImageView finish=(ImageView)convertView.findViewById(R.id.mecool_task_option_item_finish);
		System.out.println(Arrays.toString(StepIds));
		if(finishStat.get(StepIds[position])!=null){
			if(finishStat.get(StepIds[position])==1){
			finish.setVisibility(0);}
		else{
			finish.setVisibility(8);
		}
			}
		task_option_item_text.setText(newCert[position]);
		switch (ActionIds[position]) {
		case 1:
				task_option_item_img.setVisibility(0);
			break;
		case 2:
			task_option_item_img.setVisibility(8);
			break;
		case 9:
			finish.setVisibility(8);
			break;
		}
		return convertView;
	}

}
